home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / msg / clientConnect.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  3.7 KB  |  152 lines

  1. /*
  2.  *   $RCSfile: clientConnect.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:55:54 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38. #include "sysdefs.h"
  39. #include <fcntl.h>
  40. #include "ess.h"
  41. #include "checking.h"
  42. #include "trace.h"
  43. #include "error.h"
  44. #include "list.h"
  45. #include "tid.h"
  46. #include "io.h"
  47. #include "lock.h"
  48. #include "object.h"
  49. #include "msgdefs.h"
  50. #include "thread.h"
  51. #include "semaphore.h"
  52. #include "link.h"
  53. #include "host.h"
  54. #include "bitvec.h"
  55. #include "msgvector.h"
  56. #include "latch.h"
  57. #include "bf.h"
  58. #include "lsn.h"
  59. #include "volume.h"
  60. #include "openlog.h"
  61. #include "msg_funcs.h"
  62. #include "util_funcs.h"
  63. #include "thread_funcs.h"
  64. #include "msg_globals.h"
  65. #include "log_globals.h"
  66. #include "disk_globals.h"
  67.  
  68.  
  69.  void
  70. clientConnect (
  71.  
  72.     register LINK    *link 
  73. )
  74. {
  75.  
  76.     register int    fd;    
  77.     int                length;
  78.     int                socketBufSize = 16*1024; /* 16K socket buffers */
  79.  
  80.     TRPRINT(TR_MSG, TR_LEVEL_1, ("accepting on socket:%d", link->id));
  81.  
  82.     /*
  83.      *    set the address length
  84.      */
  85.     length = sizeof(SOCKADDR);
  86.     TRPRINT(TR_MSG, TR_LEVEL_2, ("length:%d", length));
  87.  
  88.     /*
  89.      *    do an accept
  90.      */
  91.     if ((fd = accept(link->id, (struct sockaddr *) &(link->address), &length)) < 0)    {
  92.  
  93.         SM_ERROR(TYPE_FATAL, errno);
  94.     }
  95.    TRPRINT(TR_MSG, TR_LEVEL_2, ("fd:%d client inet addr:%s", fd,
  96.          inet_ntoa(*(struct in_addr *)&link->address.sin_addr.s_addr)));
  97.  
  98.  
  99.  
  100.     /* 
  101.      *    Turn of TCP delay on the socket and increase the send and
  102.      *    receive buffer size
  103.      */
  104.     if (setSocketOptions(fd, socketBufSize, socketBufSize) != esmNOERROR) {
  105.         SM_ERROR(TYPE_FATAL, esmINTERNAL);
  106.     }
  107.  
  108.     /*
  109.      *    set the socket to close on exec for disk processes
  110.      */
  111.     if (fcntl(fd, F_SETFD, NULL) < 0)    {
  112.  
  113.         SM_ERROR(TYPE_FATAL, errno);
  114.     }
  115.  
  116.     /*
  117.      *    get the new link
  118.      */
  119.     link = &(Links[fd]);
  120.  
  121.     SM_ASSERT(LEVEL_1, (link->linkClass == (CL_UNUSED | CL_TIMEDOUT)));
  122.     SM_ASSERT(LEVEL_1, (link->flags == LINK_FREE));
  123.     /*
  124.      *    set the type and state of the link
  125.      */
  126.     link->linkClass = CL_CLIENT;
  127.     link->flags = LINK_ACCEPT; 
  128.         /* LINK_ACCEPT means we just accepted this cx and have not yet
  129.          * received an INIT_CLIENT message
  130.          */
  131.  
  132.     link->linkTransError = esmNOERROR;
  133.  
  134.     /*
  135.      *    set the select bit counter
  136.      */
  137.     setSelectBits(fd);
  138.  
  139.     /*
  140.      *    set the receive information
  141.      */
  142.     setLink(link);
  143.  
  144.     /*
  145.      * inc the count of active clients (used to tell if we can
  146.      * do disk i/o locally or have to pass it off to a disk process)
  147.      */
  148.     NumActiveClients++;
  149.  
  150.     /* return to main loop */
  151. }
  152.